<?php

class ZFKiller_Form extends Zend_Form {

	const GET_VALUE_TYPE_DB = 'db';
	const GET_VALUE_TYPE_DEFAULT = 'default';
	const GET_VALUE_TYPE_USER = 'user';

	public static $getValueType = null;

	public function __construct($options = null) {
		parent::__construct($options);

		$this
				->addElementPrefixPath('ZFKiller_Form_Decorator', PATH_ZFEXTEND . '/ZFKiller/Form/Decorator', Zend_Form::DECORATOR)
				->setMethod(Zend_Form::METHOD_POST)
				->addClass('zfrm')
		;
	}

	public function addClass($classname) {
		$this->setAttrib('class', trim($this->getAttrib('class') . ' ' . $classname));
		return $this;
	}

	/**
	 *
	 * @param  string|Zend_Form_Element $element
	 * @param  string $name
	 * @param  array|Zend_Config $options
	 * @throws Zend_Form_Exception on invalid element
	 * @return Zend_Form
	 */
	public function addElement($element, $name = null, $options = null) {
		$element->setAttrib('id', $this->getId() . '_' . $element->getId());

		return parent::addElement($element, $name, $options);
	}

	public function getValue($name, $getValueType = self::GET_VALUE_TYPE_DEFAULT) {
		self::$getValueType = $getValueType;
		return parent::getValue($name);
	}

	public function getValues($getValueType = self::GET_VALUE_TYPE_DEFAULT) {
		self::setGetValueType($getValueType);
		$values = parent::getValues();
		self::setGetValueType();
		return $values;
	}
    
    public function setElementsError($errorList) {
        foreach ($this->getElements() as $key => $element) {
            if (isset($errorList[$key])) {
                $element->addErrors($errorList[$key]);
            }
        }
        foreach ($this->getSubForms() as $key => $form) {
            if (isset($errorList[$key])) {
                $form->setElementsError($errorList[$key]);
            }
        }
    }

	public static function getValueType() {
		return self::$getValueType;
	}
    
	public static function setGetValueType($getValueType = self::GET_VALUE_TYPE_DEFAULT) {
		self::$getValueType = $getValueType;
	}

}